package models

import (
	"errors"
	"github.com/astaxie/beego/orm"
	"time"
)

type IpccConfigAsrKeys struct {
	Id        int
	KeyStr    string
	NumStatus int
	Describ   string
	Create    time.Time `orm:"auto_now;type(datetime)"`
	Weight    int
	Active    bool
}

func GetAllKeysStatus() ([]IpccConfigAsrKeys, error) {

	var result []IpccConfigAsrKeys

	o := orm.NewOrm()
	o.Using("default")

	num, err := o.QueryTable("IpccConfigAsrKeys").Filter("Active", true).OrderBy("Weight").All(&result)
	if err != nil {
		return nil, err
	}

	if 0 == num {
		return nil, errors.New("no keys")
	}

	return result, nil
}

func RegAsrKeys() {
	orm.RegisterModel(new(IpccConfigAsrKeys))
}
